#ifndef FPRINTTHREAD_H
#define FPRINTTHREAD_H

#include <QThread>
#include <QDebug>
extern "C"
{
    #include <libfprint/fprint.h>
}

class FprintThread : public QThread
{
    Q_OBJECT

private:
    struct fp_dev *openedDevice;
    int fingerprint;
    int status;
    struct fp_print_data *data;
    struct fp_img *img;

public:
    FprintThread(QObject *parent = 0)
    {
        openedDevice = NULL;
        status = -1;
        fingerprint = -1;
        // fp_print_data *data = NULL;
    }

    void run()
    {
        int status = fp_enroll_finger_img(openedDevice, &data, &img);
        while(status != FP_ENROLL_COMPLETE)
        {
            emit statusChanged(status);
            sleep(1);
            emit statusChanged(-1);
            status = fp_enroll_finger_img(openedDevice, &data, &img);
        }
        // Update status on the enrolldialog
        emit statusChanged(status);
        // Save fingerprint binary data
        fp_print_data_save(data, (fp_finger)fingerprint);

        // Make the fp_print_data free
        fp_print_data_free(data);
        data = NULL;
    }
    void set(fp_dev *dv, int fp)
    {
        this->openedDevice = dv;
        this->fingerprint = fp;
    }

signals:
    void statusChanged(int status);

};

#endif // FPRINTTHREAD_H
